using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

namespace AnTunes.Utils.MPG123
{
	class MPG123Decoder
	{				
		public MPG123Decoder (Stream stream)
		{			
			MPGImport.GlobalInit();
			IntPtr errorPtr;
			handle_ = MPGImport.mpg123_new(null, errorPtr);
		
			MPGImport.CheckResult( MPGImport.mpg123_open_feed(handle_) );
			//MPGImport.CheckResult( MPGImport.mpg123_replace_reader_handle(handle_, ReadCallback, SeekCallback, null) );
			
			const int headerSize = 32768;
			byte[] header = new byte[headerSize];
			int size = stream.Read(header, 0, headerSize);
			
			MPGImport.mpg123_feed(
					handle_, 
					Marshal.UnsafeAddrOfPinnedArrayElement(header, 0), size
				);
			
			long rate;
			int channels;
			int encoding;
			MPGImport.CheckResult( MPGImport.mpg123_getformat(handle_, out rate, out channels, out encoding) );
			MPG123.MPGImport.mpg123_getparam
		}
		
		~MPG123Decoder()
		{
			MPGImport.GlobalFree();
		}
		
		static int ReadCallback(IntPtr thisPtr, IntPtr data, int size)
		{
			return 0;
		}
			
		static int SeekCallback(IntPtr handle, IntPtr o, int size)
		{
			return 0;
		}
		
		private IntPtr handle_;
		private Stream stream_;
	}
}

